#include <stc8h.h>
#include "INTRINS.H"




#define VERF (*(unsigned int volatile xdata *)0xfde7)

void ADCInit()
{
    P_SW2 |= 0x80;
    ADCTIM = 0x3f;                              //设置ADC内部时序
    ADCCFG = 0x2f;                              //设置ADC时钟为系统时钟/2/16
    ADC_CONTR = 0x8f;                           //使能ADC模块,并选择第15通道
    ADCEXCFG=0x0f;
}

int ADCRead()
{
    int res;
    unsigned int xdata * verfprt;
    verfprt=(unsigned int xdata *) 0xfde7;
    ADC_CONTR |= 0x40;                          //启动AD转换
    _nop_();
    _nop_();
    while (!(ADC_CONTR & 0x20));                //查询ADC完成标志
    ADC_CONTR &= ~0x20;                         //清完成标志
    res = (ADC_RES << 8) | ADC_RESL;            //读取ADC结果

    return (int)(4096L* (*verfprt) /res);
}


void ADCdown(){
    ADC_CONTR = 0x0f; 
}